package com.javarush.test.level14.lesson08.bonus01;

import java.util.ArrayList;
import java.util.List;

/* Нашествие эксепшенов
Заполни массив exceptions 10 различными эксепшенами.
Первое исключение уже реализовано в методе initExceptions.
*/

public class Solution
{
    public static List<Exception> exceptions = new ArrayList<Exception>();

    public static void main(String[] args)
    {
        initExceptions();

        for (Exception exception : exceptions)
        {
            System.out.println(exception);
        }
    }

    private static void initExceptions()
    {   //it's first exception
        //1 java.lang.ArithmeticException: / by zero
        try
        {
            float i = 1 / 0;

        } catch (Exception e)
        {
            exceptions.add(e);
        }

        //Add your code here
        //2 java.lang.NullPointerException
        try {
            Object obj = null;
            obj.toString();
        } catch (Exception e) {
            exceptions.add(e);
        }

        //3 java.lang.StringIndexOutOfBoundsException: String index out of range: 9000
        try {
            "123".charAt(9000);
        } catch (Exception e) {
            exceptions.add(e);
        }

        //4 java.lang.ArrayIndexOutOfBoundsException: 1
        try {
            int[] arr = {1};
            arr[1] = 5;
        } catch (Exception e) {
            exceptions.add(e);
        }

        //5 java.lang.ClassNotFoundException: java.lang.Stringus
        try {
            Class c = Class.forName("java.lang.Stringus");
        } catch (Exception e) {
            exceptions.add(e);
        }

        //6 java.lang.ArrayStoreException: java.lang.Integer
        try {
            Object[] arr = new String[]{"1", "2"};
            arr[0] = 2;
        } catch (Exception e) {
            exceptions.add(e);
        }

        //7 java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
        try {
            Object o = Integer.valueOf(100500);
            String s = (String)o;
        } catch (Exception e) {
            exceptions.add(e);
        }

        //8 java.lang.CloneNotSupportedException: com.javarush.test.level14.lesson08.bonus01.Solution
        try {
            Solution s = new Solution();
            Object s2 = s.clone();
        } catch (Exception e) {
            exceptions.add(e);
        }

        //9 java.lang.NegativeArraySizeException
        try {
            int[] a = new int[-1];
        } catch (Exception e) {
            exceptions.add(e);
        }

        //10 java.lang.NumberFormatException: For input string: "lala"
        try {
            int a = Integer.parseInt("lala");
        } catch (Exception e) {
            exceptions.add(e);
        }
    }
}
